package com.feng.study.demo.collectionLearn;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: Zeng ShaoYong
 * @Date: 2022-05-17
 * @Description:
 */
public class ListDemo02 {
    public static void main(String[] args) {
        LinkedList<String> list = new LinkedList<>();
        ArrayList<String> arrayList = new ArrayList<>(10);
//        System.out.println(arrayList.get(0)); //报错，懒加载
        arrayList.add("1");
//        arrayList.set(7,"2");  //报错，超出范围  java.lang.IndexOutOfBoundsException
//        System.out.println(arrayList.get(7));  //报错，超出范围

        //线程安全的,三种
        Vector<String> vector= new Vector<>();
        List<String> synchronizedList = Collections.synchronizedList(list);
        copyOnWriteArrayListDemo();
    }

    private static void copyOnWriteArrayListDemo() {
        CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>();
        list.add(5);
        list.add(9);
        list.set(1,999);
        System.out.println(list.get(1));
        System.out.println(list);
    }
}
